﻿#region #region Copyright (C) 2005-2011 Team MediaPortal

// 
// Copyright (C) 2005-2011 Team MediaPortal
// http://www.team-mediaportal.com
// 
// MediaPortal is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
// 
// MediaPortal is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
// 

#endregion

using System.Collections.Generic;
using MediaPortal.GUI.Library;
using MyUPnPSupport.Plugin.Window.Items;

namespace MyUPnPSupport.Plugin.Window.Dialogs {
    public static class ContextMenu {

        private static List<IMenuItem> CurrentMenuItems { get; set; }

        internal static void ShowContextMenu(string headerLabel, List<IMenuItem> listCurrentContextMenuItems) {
            IDialogbox contextMenu =
            (IDialogbox) GUIWindowManager.GetWindow((int) GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (contextMenu == null) {
                return;
            }
            if (CurrentMenuItems == null) {
                return;
            }
            contextMenu.Reset();
            if (listCurrentContextMenuItems == null || listCurrentContextMenuItems.Count <= 0) {
                listCurrentContextMenuItems = CurrentMenuItems;
            }
            CurrentMenuItems = listCurrentContextMenuItems;
            contextMenu.SetHeading(headerLabel ?? "Current Context Menu:");
            listCurrentContextMenuItems.ForEach(item => contextMenu.Add(item.Name));
            contextMenu.DoModal(GUIWindowManager.ActiveWindow);
            if (contextMenu.SelectedId > 0) {
                listCurrentContextMenuItems[contextMenu.SelectedId - 1].OnClicked(null, null);
            }
        }
    }
}